<?php
!defined("ROOT_PATH") && exit('No direct script access allowed');
/**
* weshuo microblog platform
* @copyright  (c) 2010-2011 weshuo team http://www.weshuo.org
* @license  Mozilla Public License (MPL 1.1)
* @author iceweb
*/
class BaseTemplate
{
	function __construct(){
		if(AppAction::$conn){
			mysql_close(AppAction::$conn);
		}
	}
	private static $data=array();
	public static function loadTemplate($tpl,$data)
	{
		$file=self::loadFile($tpl);
		if($file)
		{
			$title=ViewData::$title;
			$keywords=ViewData::$keywords;
			$description=ViewData::$description;
			$page=ViewData::$page;
			$body=ViewData::$body;
			$form_data =ViewData::$form_data;
			$form_hint =ViewData::$form_hint;
			if($body){
				foreach ($body as $key=>$value){
					$$key=$value;
				}
			}
			require $file;
			ob_start();
			$buffer = ob_get_contents();
			@ob_end_clean();
			exit;
			return $buffer;
		}
		else 
		{
			return false;
		}
		
	}
	
	public static function loadSubTemplate($tpl)
	{
		$file=self::loadFile($tpl);
		if($file)
		{
			@extract(self::$data);
			require $file;
		}
	}
	
	private static function loadFile($tplName)
	{
		$file=APP_VIEW_PATH.$tplName.'.php';
		if(!file_exists($file))
		{
			return FALSE;
		}
		return $file;
	}
}
